/**
 * @file foobar_version.h
 * @author Vincent Wei (https://github.com/VincentWei)
 * @date 2021/09/18
 * @brief The version of FooBar.
 *
 * Copyright (C) 2021 FMSoft <https://www.fmsoft.cn>
 *
 * This file is a part of FooBar, which contains the examples of my course:
 * _the Best Practices of C Language_.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the “Software”), to
 * deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom
 * the Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 */

#ifndef FOOBAR_FOOBAR_VERSION_H
#define FOOBAR_FOOBAR_VERSION_H

#include "foobar-macros.h"

/**
 * FOOBAR_VERSION_MAJOR:
 *
 * Like foobar_get_major_version(), but from the headers used at
 * application compile time, rather than from the library linked
 * against at application run time.
 *
 * Since 0.0.1
 */
#define FOOBAR_VERSION_MAJOR (0)

/**
 * FOOBAR_VERSION_MINOR:
 *
 * Like foobar_get_minor_version(), but from the headers used at
 * application compile time, rather than from the library linked
 * against at application run time.
 *
 * Since 0.0.1
 */
#define FOOBAR_VERSION_MINOR (0)

/**
 * FOOBAR_VERSION_MICRO:
 *
 * Like foobar_get_micro_version(), but from the headers used at
 * application compile time, rather than from the library linked
 * against at application run time.
 *
 * Since 0.0.1
 */
#define FOOBAR_VERSION_MICRO (1)

#define FOOBAR_VERSION_STRING ("0.0.1")

/**
 * FOOBAR_CHECK_VERSION:
 *
 * @major: major version (e.g. 1 for version 1.2.5)
 * @minor: minor version (e.g. 2 for version 1.2.5)
 * @micro: micro version (e.g. 5 for version 1.2.5)
 *
 * Returns: %TRUE if the version of the FooBar header files
 * is the same as or newer than the passed-in version.
 *
 * Since 0.0.1
 */
#define FOOBAR_CHECK_VERSION(major, minor, micro) \
    (FOOBAR_VERSION_MAJOR > (major) || \
    (FOOBAR_VERSION_MAJOR == (major) && FOOBAR_VERSION_MINOR > (minor)) || \
    (FOOBAR_VERSION_MAJOR == (major) && FOOBAR_VERSION_MINOR == (minor) && \
     FOOBAR_VERSION_MICRO >= (micro)))

FOOBAR_EXTERN_C_BEGIN

/**
 * foobar_get_major_version:
 *
 * Returns: The major version of FooBar.
 *
 * Since 0.0.1
 */
FOOBAR_INLINE int
foobar_get_major_version(void)
{
    return FOOBAR_VERSION_MAJOR;
}

/**
 * foobar_get_minor_version:
 *
 * Returns: The minor version of FooBar.
 *
 * Since 0.0.1
 */
FOOBAR_INLINE int
foobar_get_minor_version(void)
{
    return FOOBAR_VERSION_MINOR;
}

/**
 * foobar_get_micro_version:
 *
 * Returns: The micro version of FooBar.
 *
 * Since 0.0.1
 */
FOOBAR_INLINE int
foobar_get_micro_version(void)
{
    return FOOBAR_VERSION_MICRO;
}

/**
 * foobar_get_versions:
 *
 * @major: the buffer for major version (nullable).
 * @minor: the buffer for minor version (nullable).
 * @micro: the buffer for micro version (nullable).
 *
 * Returns: none.
 *
 * Since 0.0.1
 */
FOOBAR_INLINE void
foobar_get_versions (int *major, int *minor, int *micro) {
    if (major) *major = FOOBAR_VERSION_MAJOR;
    if (minor) *minor = FOOBAR_VERSION_MINOR;
    if (micro) *micro = FOOBAR_VERSION_MICRO;
}

/**
 * foobar_version_string:
 *
 * Returns: the pointer to the FooBar version string, e.g.,
 * "1.2.3" for version 1.2.3.
 *
 * Since 0.0.1
 */
FOOBAR_INLINE const char *
foobar_get_version_string (void) {
    return FOOBAR_VERSION_STRING;
}

FOOBAR_EXTERN_C_END

#endif /* not defined FOOBAR_FOOBAR_VERSION_H */
